﻿<script type="text/javascript" src="/public/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/public/js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="/public/js/flexigrid.js"></script>
<script type="text/javascript" src="/public/js/jquery.simple.tree.js"></script>
<script src="/public/css/admin/category/nyroModal-1.3.0/js/jquery.nyroModal-1.3.0.pack.js"></script> 
<script type="text/javascript" src="/public/js/jquery-1.2.3.pack.js"></script>


<link rel="stylesheet" type="text/css" href="/public/css/flexigrid/flexigrid/flexigrid.css">
<link rel="stylesheet" media="screen" type="text/css" href="/public/css/admin/category/style.css" />
<link rel="stylesheet" href="/public/css/admin/category/nyroModal-1.3.0/styles/nyroModal.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="/public/css/standard/column.css" />

<script>
	$(document).ready(function(){ 
		$("#flexme1").flexigrid(
		{
			colModel : [
				{display: 'ID', name : 'id', width : 40, sortable : true, align: 'center'},
				{display: 'Nhà sản xuất', name : 'nhasanxuat', width : 180, sortable : true, align: 'center'},
				{display: 'Xuất xứ', name : 'xuatxu', width : 120, sortable : true, align: 'center'},
				{display: 'Trang chủ', name : 'link', width : 130, sortable : true, align: 'center'},
				{display: 'Avatar', name : 'avatar', width : 80, sortable : true, align: 'center'}
				],

			buttons : [
				{name: 'Add', bclass: 'add',onpress : test},
				{name: 'Delete', bclass: 'delete',onpress : test},
				{separator: true}
				],
			title:'Nhà cung cấp',
			userpager: true,
			userRp:true,
			singleSelect: true,
			rp:10,
			width:700,
			height:200,
			
		}
		);
			
		function test(com,grid) 
			{
				if (com=='Delete')
					{
							//$('.trSelected', grid).each(function() {
							/*var id = $(this).attr('id');
							alert("Delete row " + id);*/
							//}
						
					}
				else if (com=='Add')
					{
						alert('Add New Item');
						$.nyroModalManual({
							url: 'http://shoppingcartcnpm.orgfree.com/index.php/Longadmin/admin/add',
							width: 500, // default Width If null, will be calculate automatically
							height: 500, // default Height If null, will be calculate automatically
							minWidth: null, // Minimum width
							minHeight: null, // Minimum height
							endRemove: function() {window.location.reload()}
						});	
					}			
			}
			

	});	
</script>

<script type="text/javascript">        
	$(document).ready(function(){	
		
		$(".edit").click(function(){ 
			supplierID = $(this).parent("div").parent("td").attr("id");
			alert('Edit Item'+ supplierID);	
			$.nyroModalManual({
				url: 'http://shoppingcartcnpm.orgfree.com/index.php/Longadmin/admin/updatesup?id='+supplierID,
				width: 500, // default Width If null, will be calculate automatically
				height: 500, // default Height If null, will be calculate automatically
				minWidth: null, // Minimum width
				minHeight: null, // Minimum height
				endRemove: function() {window.location.reload()}
			});	
		});
	});
</script>


<script type="text/javascript">  
	$(document).ready(function(){ 
		$("#tablecatdes").flexigrid(
		{
			url:'http://shoppingcartcnpm.orgfree.com/index.php/Longadmin/admin/catdes',
			dataType: 'json',
			colModel : [
				{display: 'Catdes_ID', name : 'catdes_id', width : 40, sortable : true, align: 'center'},
				{display: 'Cat_ID', name : 'cat_id', width : 180, sortable : true, align: 'center'},
				{display: 'Catdes_ten', name : 'catdes_ten', width : 120, sortable : true, align: 'center'},
				],

			buttons : [
				{name: 'Add', bclass: 'add',onpress : test},
				{name: 'Delete', bclass: 'delete',onpress : test},
				{separator: true}
				],
			title:'Nhà cung cấp',
			userpager: true,
			userRp:true,
			singleSelect: true,
			rp:10,
			width:400,
			height:200,
			
		}
		);
			
		function test(com,grid) 
			{
				if (com=='Delete')
					{
						
					}
				else if (com=='Add')
					{
						alert('Add New Item');
						$.nyroModalManual({
							url: 'http://shoppingcartcnpm.orgfree.com/index.php/Longadmin/admin/add',
							width: 500, // default Width If null, will be calculate automatically
							height: 500, // default Height If null, will be calculate automatically
							minWidth: null, // Minimum width
							minHeight: null, // Minimum height
							endRemove: function() {window.location.reload()}
						});	
					}			
			}
			

	});	
</script>







<?php 
	$db = Zend_Registry::get('db');
	$table = 'supplier';
	$select = $db->select()->from($table);
	$suppliers = $db->query($select)->fetchAll();
?>


<table id="flexme1">

 <tbody>
	<?php echo $this->partialLoop('supplier/_supplier.phtml',$suppliers); ?>
 </tbody>
</table>

<style>
	
	.flexigrid div.fbutton .add
		{
			background: url(/public/css/flexigrid/images/add.png) no-repeat center left;
		}	

	.flexigrid div.fbutton .delete
		{
			background: url(/public/css/flexigrid/images/close.png) no-repeat center left;
		}	

</style>


<script type="text/javascript">   
		jQuery.noConflict();
		var simpleTreeCollection;
			
		$(document).ready(function(){ 
			
			simpleTreeCollection = $('.simpleTree').simpleTree({
				
				autoclose: false,
				docToFolderConvert: false,
				
				afterClick:function(node){
					//// nothing to do for now...
					categoryId = $('span:first',node).parent("li").attr("id");
					$.get('http://shoppingcartcnpm.orgfree.com/index.php/Longadmin/category/catdesajax', {id:categoryId}, function(data) {
						//alert("Data:"+datatest[0].catdes_ten);
						$('#textAjax').html(data).hide().fadeIn(1000);
					});
					//jQuery("#test").text('Id cua category :' + categoryId); 
					

				},
				
				afterDblClick:function(node){
					categoryId = $('span:first',node).parent("li").attr("id");
					parentId = $('span:first',node).parent("li").parent("ul").parent("li").attr("id");
				
					$.nyroModalManual({
						url: '/application/models/ajax/category/update.php?cat_id='+categoryId,
						width: 250, // default Width If null, will be calculate automatically
						height: 130, // default Height If null, will be calculate automatically
						minWidth: null, // Minimum width
						minHeight: null, // Minimum height
						endRemove: function() {window.location.reload()}
					});		
	
					return false;
							
				},			
				afterMove:function(){	
					var serialStr = "";
					var order = "";
					$("ul.simpleTree li span").each(function(){			
						parentId = $(this).parent("li").parent("ul").parent("li").attr("id");
						if (parentId == undefined) parentId = "root";
						order = (($(this).parent("li").prevAll("li").size()+1))/2; 
						if ( parentId != "root") serialStr += ""+parentId+":"+$(this).parent("li").attr("id")+":"+order+"|";
					});
					$.ajax({
					   type: "POST",
					   url: "/application/models/ajax/category/saveData.php",
					   data: "serialized="+serialStr,
					   success: function(msg){
					   	 $("#serializedList").html(msg);
					   }
					 });
			
					return false;
					
				},
				docToFolderConvert: false,
				afterAjax:function()
				{
					//alert('Loaded');
				},
				animate:true
			});	
			
			$(".add_category").click(function(){
				categoryId = $(this).parent("li").attr("id");
				$.nyroModalManual({
					url: '/application/models/ajax/category/add.php?cat_parentID='+categoryId,
					width: 280, // default Width If null, will be calculate automatically
					height: 200, // default Height If null, will be calculate automatically
					minWidth: null, // Minimum width
					minHeight: null, // Minimum height
					resizeable: true,
					endRemove: function() {window.location.reload()}
					
				});
			});
			
			$(".delete_category").click(function(){
				parentId = $(this).parent("li").attr("id");
				category_name = $(this).siblings("span").text();
				$.nyroModalManual({
					url: '/application/models/ajax/category/delete.php?cat_parentID='+parentId+'&cat_ten='+category_name,
					endRemove: function() {window.location.reload()},
					width: 450, // default Width If null, will be calculate automatically
					height: 150, // default Height If null, will be calculate automatically
					minWidth: null, // Minimum width
					minHeight: null, // Minimum height
					resizeable: false, // Indicate if the content is resizable. Will be set to false for swf
					autoSizable: false, // Indicate if the content is auto sizable. If not, the min size will be used
					padding: 0 // padding for the max modal size	
				});
			});			
			//$("#flexme1").flexigrid();	
		});
</script>
<?php 
		// Cai nay phai de o controller, nhung ma gio chua biet, hix
		$db = Zend_Registry::get('db');
		$table = 'category';
		
		$select = $db->select()->from($table);
		$category = $db->query($select)->fetchAll();
		// chua biet xu ly the nao day, hix, sao lai  bi the nay nhi?  :@
		// Cai nay se cho vao trong ham helper moi dung chuan :D, gio cu the da 
		function createTree($array, $currentParent, $currLevel = 0, $prevLevel = -1) {
				
			foreach ($array as $category) {
				
				if ($currentParent == $category['cat_parentID']) {						
					
					if ($currLevel > $prevLevel) echo " <ul> \n"; 
					
					if ($currLevel == $prevLevel) echo " </li> \n";
					
					echo '<li id="'.$category['cat_id'].'"><span>'.$category['cat_ten'].'</span><img src="/public/css/admin/category/images/16-circle-blue-add.png" alt="add subcategory" width="16" height="16" class="add_category"/> <img src="/public/css/admin/category/images/16-circle-red-remove.png" alt="remove" width="16" height="16" class="delete_category"/>';
								
					if ($currLevel > $prevLevel) { $prevLevel = $currLevel; }
					
					$currLevel++; 

					createTree ($array, $category['cat_id'], $currLevel, $prevLevel);
					
					$currLevel--;	 		 	

				}	

			}
			
			if ($currLevel == $prevLevel) echo "\n </li> \n </ul> \n";

		}	
?>
	

	<ul class="simpleTree">
		<li id="0" class="root"><span>Categories</span><img src="/public/css/admin/category/images/16-circle-blue-add.png" alt="add subcategory" width="16" height="16" class="add_category"/> <img src="/public/css/admin/category/images/16-circle-red-remove.png" alt="remove" width="16" height="16" class="delete_category"/>
			<?php createTree($category, 0); ?>
		</li>
	</ul>
	<div id="colright">
		<div id= "textAjax"></div>
	</div>
<br />

<table id = "tablecatdes" style="display:none">
</table>	
<br />
<br />
????????????????????????????????????????	
<?php echo $this->render('admin/_product.phtml'); ?>	
	